package com.mob.tools.utils;

import android.text.TextUtils;
import android.util.Base64;
import com.mob.tools.MobLog;
import com.mob.tools.log.NLog;
import com.mob.tools.network.BufferedByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URLEncoder;
import java.security.KeyFactory;
import java.security.MessageDigest;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.zip.CRC32;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public class Data
{
  private static final String CHAT_SET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

  public static String AES128Decode(String paramString, byte[] paramArrayOfByte)
    throws Throwable
  {
    if ((paramString == null) || (paramArrayOfByte == null))
      return null;
    return new String(AES128Decode(paramString.getBytes("UTF-8"), paramArrayOfByte), "UTF-8");
  }

  public static byte[] AES128Decode(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
    throws Throwable
  {
    if ((paramArrayOfByte1 == null) || (paramArrayOfByte2 == null))
      return null;
    byte[] arrayOfByte1 = new byte[16];
    System.arraycopy(paramArrayOfByte1, 0, arrayOfByte1, 0, Math.min(paramArrayOfByte1.length, 16));
    SecretKeySpec localSecretKeySpec = new SecretKeySpec(arrayOfByte1, "AES");
    Cipher localCipher = Cipher.getInstance("AES/ECB/NoPadding", "BC");
    localCipher.init(2, localSecretKeySpec);
    byte[] arrayOfByte2 = new byte[localCipher.getOutputSize(paramArrayOfByte2.length)];
    int i = localCipher.update(paramArrayOfByte2, 0, paramArrayOfByte2.length, arrayOfByte2, 0);
    (i + localCipher.doFinal(arrayOfByte2, i));
    return arrayOfByte2;
  }

  public static byte[] AES128Encode(String paramString1, String paramString2)
    throws Throwable
  {
    if ((paramString1 == null) || (paramString2 == null))
      return null;
    byte[] arrayOfByte1 = paramString1.getBytes("UTF-8");
    byte[] arrayOfByte2 = new byte[16];
    System.arraycopy(arrayOfByte1, 0, arrayOfByte2, 0, Math.min(arrayOfByte1.length, 16));
    byte[] arrayOfByte3 = paramString2.getBytes("UTF-8");
    SecretKeySpec localSecretKeySpec = new SecretKeySpec(arrayOfByte2, "AES");
    Cipher localCipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
    localCipher.init(1, localSecretKeySpec);
    byte[] arrayOfByte4 = new byte[localCipher.getOutputSize(arrayOfByte3.length)];
    localCipher.doFinal(arrayOfByte4, localCipher.update(arrayOfByte3, 0, arrayOfByte3.length, arrayOfByte4, 0));
    return arrayOfByte4;
  }

  public static byte[] AES128Encode(byte[] paramArrayOfByte, String paramString)
    throws Throwable
  {
    if ((paramArrayOfByte == null) || (paramString == null))
      return null;
    return AES128Encode(paramArrayOfByte, paramString.getBytes("UTF-8"));
  }

  public static byte[] AES128Encode(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
    throws Throwable
  {
    SecretKeySpec localSecretKeySpec = new SecretKeySpec(paramArrayOfByte1, "AES");
    Cipher localCipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
    localCipher.init(1, localSecretKeySpec);
    byte[] arrayOfByte = new byte[localCipher.getOutputSize(paramArrayOfByte2.length)];
    localCipher.doFinal(arrayOfByte, localCipher.update(paramArrayOfByte2, 0, paramArrayOfByte2.length, arrayOfByte, 0));
    return arrayOfByte;
  }

  public static String Base64AES(String paramString1, String paramString2)
  {
    String str1;
    if ((paramString1 == null) || (paramString2 == null))
      str1 = null;
    while (true)
    {
      return str1;
      str1 = null;
      try
      {
        str1 = Base64.encodeToString(AES128Encode(paramString2, paramString1), 0);
        if ((!TextUtils.isEmpty(str1)) && (str1.contains("\n")))
        {
          String str2 = str1.replace("\n", "");
          return str2;
        }
      }
      catch (Throwable localThrowable)
      {
        MobLog.getInstance().w(localThrowable);
      }
    }
    return str1;
  }

  public static String CRC32(byte[] paramArrayOfByte)
    throws Throwable
  {
    CRC32 localCRC32 = new CRC32();
    localCRC32.update(paramArrayOfByte);
    long l = localCRC32.getValue();
    StringBuilder localStringBuilder = new StringBuilder();
    int i = (byte)(int)(l >>> 56);
    Object[] arrayOfObject1 = new Object[1];
    arrayOfObject1[0] = Integer.valueOf(i & 0xFF);
    localStringBuilder.append(String.format("%02x", arrayOfObject1));
    int j = (byte)(int)(l >>> 48);
    Object[] arrayOfObject2 = new Object[1];
    arrayOfObject2[0] = Integer.valueOf(j & 0xFF);
    localStringBuilder.append(String.format("%02x", arrayOfObject2));
    int k = (byte)(int)(l >>> 40);
    Object[] arrayOfObject3 = new Object[1];
    arrayOfObject3[0] = Integer.valueOf(k & 0xFF);
    localStringBuilder.append(String.format("%02x", arrayOfObject3));
    int m = (byte)(int)(l >>> 32);
    Object[] arrayOfObject4 = new Object[1];
    arrayOfObject4[0] = Integer.valueOf(m & 0xFF);
    localStringBuilder.append(String.format("%02x", arrayOfObject4));
    int n = (byte)(int)(l >>> 24);
    Object[] arrayOfObject5 = new Object[1];
    arrayOfObject5[0] = Integer.valueOf(n & 0xFF);
    localStringBuilder.append(String.format("%02x", arrayOfObject5));
    int i1 = (byte)(int)(l >>> 16);
    Object[] arrayOfObject6 = new Object[1];
    arrayOfObject6[0] = Integer.valueOf(i1 & 0xFF);
    localStringBuilder.append(String.format("%02x", arrayOfObject6));
    int i2 = (byte)(int)(l >>> 8);
    Object[] arrayOfObject7 = new Object[1];
    arrayOfObject7[0] = Integer.valueOf(i2 & 0xFF);
    localStringBuilder.append(String.format("%02x", arrayOfObject7));
    int i3 = (byte)(int)l;
    Object[] arrayOfObject8 = new Object[1];
    arrayOfObject8[0] = Integer.valueOf(i3 & 0xFF);
    localStringBuilder.append(String.format("%02x", arrayOfObject8));
    while (localStringBuilder.charAt(0) == '0')
      localStringBuilder = localStringBuilder.deleteCharAt(0);
    return localStringBuilder.toString().toLowerCase();
  }

  public static String MD5(File paramFile)
  {
    if ((paramFile == null) || (!paramFile.exists()));
    while (true)
    {
      return null;
      try
      {
        FileInputStream localFileInputStream = new FileInputStream(paramFile);
        byte[] arrayOfByte = rawMD5(localFileInputStream);
        localFileInputStream.close();
        if (arrayOfByte != null)
          return toHex(arrayOfByte);
      }
      catch (Throwable localThrowable)
      {
        MobLog.getInstance().w(localThrowable);
      }
    }
    return null;
  }

  public static String MD5(String paramString)
  {
    if (paramString == null);
    byte[] arrayOfByte;
    do
    {
      return null;
      arrayOfByte = rawMD5(paramString);
    }
    while (arrayOfByte == null);
    return toHex(arrayOfByte);
  }

  public static String MD5(byte[] paramArrayOfByte)
  {
    if (paramArrayOfByte == null);
    byte[] arrayOfByte;
    do
    {
      return null;
      arrayOfByte = rawMD5(paramArrayOfByte);
    }
    while (arrayOfByte == null);
    return toHex(arrayOfByte);
  }

  public static byte[] SHA1(File paramFile)
  {
    if ((paramFile == null) || (!paramFile.exists()))
      return null;
    byte[] arrayOfByte = null;
    try
    {
      FileInputStream localFileInputStream = new FileInputStream(paramFile);
      arrayOfByte = SHA1(localFileInputStream);
      localFileInputStream.close();
      return arrayOfByte;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
    return arrayOfByte;
  }

  public static byte[] SHA1(InputStream paramInputStream)
  {
    if (paramInputStream == null)
      return null;
    try
    {
      byte[] arrayOfByte1 = new byte[1024];
      MessageDigest localMessageDigest = MessageDigest.getInstance("SHA-1");
      for (int i = paramInputStream.read(arrayOfByte1); i != -1; i = paramInputStream.read(arrayOfByte1))
        localMessageDigest.update(arrayOfByte1, 0, i);
      byte[] arrayOfByte2 = localMessageDigest.digest();
      return arrayOfByte2;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
    return null;
  }

  public static byte[] SHA1(String paramString)
    throws Throwable
  {
    if (TextUtils.isEmpty(paramString))
      return null;
    return SHA1(paramString.getBytes("utf-8"));
  }

  public static byte[] SHA1(byte[] paramArrayOfByte)
    throws Throwable
  {
    MessageDigest localMessageDigest = MessageDigest.getInstance("SHA-1");
    localMessageDigest.update(paramArrayOfByte);
    return localMessageDigest.digest();
  }

  public static String base62(long paramLong)
  {
    String str;
    if (paramLong == 0L)
      str = "0";
    while (paramLong > 0L)
    {
      int i = (int)(paramLong % 62L);
      paramLong /= 62L;
      str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".charAt(i) + str;
      continue;
      str = "";
    }
    return str;
  }

  public static String byteToHex(byte[] paramArrayOfByte)
  {
    return byteToHex(paramArrayOfByte, 0, paramArrayOfByte.length);
  }

  public static String byteToHex(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    if (paramArrayOfByte == null)
      return localStringBuffer.toString();
    for (int i = paramInt1; i < paramInt2; i++)
    {
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[0] = Byte.valueOf(paramArrayOfByte[i]);
      localStringBuffer.append(String.format("%02x", arrayOfObject));
    }
    return localStringBuffer.toString();
  }

  public static byte[] rawMD5(InputStream paramInputStream)
  {
    if (paramInputStream == null)
      return null;
    try
    {
      byte[] arrayOfByte1 = new byte[1024];
      MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
      for (int i = paramInputStream.read(arrayOfByte1); i != -1; i = paramInputStream.read(arrayOfByte1))
        localMessageDigest.update(arrayOfByte1, 0, i);
      byte[] arrayOfByte2 = localMessageDigest.digest();
      return arrayOfByte2;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
    return null;
  }

  public static byte[] rawMD5(String paramString)
  {
    if (paramString == null)
      return null;
    try
    {
      byte[] arrayOfByte = rawMD5(paramString.getBytes("utf-8"));
      return arrayOfByte;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
    return null;
  }

  public static byte[] rawMD5(byte[] paramArrayOfByte)
  {
    if (paramArrayOfByte == null)
      return null;
    try
    {
      ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(paramArrayOfByte);
      byte[] arrayOfByte = rawMD5(localByteArrayInputStream);
      localByteArrayInputStream.close();
      return arrayOfByte;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
    return null;
  }

  public static byte[] rawRSADecode(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, int paramInt)
    throws Throwable
  {
    KeyFactory.getInstance("RSA");
    PKCS8EncodedKeySpec localPKCS8EncodedKeySpec = new PKCS8EncodedKeySpec(paramArrayOfByte2);
    RSAPrivateKey localRSAPrivateKey = (RSAPrivateKey)KeyFactory.getInstance("RSA").generatePrivate(localPKCS8EncodedKeySpec);
    Cipher localCipher = Cipher.getInstance("RSA/None/PKCS1Padding");
    localCipher.init(2, localRSAPrivateKey);
    int i = 0;
    int j = paramInt / 8;
    BufferedByteArrayOutputStream localBufferedByteArrayOutputStream = new BufferedByteArrayOutputStream();
    while (paramArrayOfByte1.length - i > 0)
    {
      byte[] arrayOfByte = localCipher.doFinal(paramArrayOfByte1, i, Math.min(paramArrayOfByte1.length - i, j));
      localBufferedByteArrayOutputStream.write(arrayOfByte, 0, arrayOfByte.length);
      i += j;
    }
    localBufferedByteArrayOutputStream.close();
    return localBufferedByteArrayOutputStream.toByteArray();
  }

  public static byte[] rawRSAEncode(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2, int paramInt)
    throws Throwable
  {
    int i = -11 + paramInt / 8;
    X509EncodedKeySpec localX509EncodedKeySpec = new X509EncodedKeySpec(paramArrayOfByte2);
    RSAPublicKey localRSAPublicKey = (RSAPublicKey)KeyFactory.getInstance("RSA").generatePublic(localX509EncodedKeySpec);
    Cipher localCipher = Cipher.getInstance("RSA/None/PKCS1Padding");
    localCipher.init(1, localRSAPublicKey);
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    int j = 0;
    while (paramArrayOfByte1.length - j > 0)
    {
      byte[] arrayOfByte = localCipher.doFinal(paramArrayOfByte1, j, Math.min(paramArrayOfByte1.length - j, i));
      localByteArrayOutputStream.write(arrayOfByte, 0, arrayOfByte.length);
      j += i;
    }
    localByteArrayOutputStream.close();
    return localByteArrayOutputStream.toByteArray();
  }

  private static String toHex(byte[] paramArrayOfByte)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    for (int i = 0; i < paramArrayOfByte.length; i++)
    {
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[0] = Byte.valueOf(paramArrayOfByte[i]);
      localStringBuffer.append(String.format("%02x", arrayOfObject));
    }
    return localStringBuffer.toString();
  }

  public static String urlEncode(String paramString)
  {
    try
    {
      String str = urlEncode(paramString, "utf-8");
      return str;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
    return null;
  }

  public static String urlEncode(String paramString1, String paramString2)
    throws Throwable
  {
    String str = URLEncoder.encode(paramString1, paramString2);
    if (TextUtils.isEmpty(str))
      return str;
    return str.replace("+", "%20");
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.mob.tools.utils.Data
 * JD-Core Version:    0.6.2
 */